/**
 * 医师处方权查看
 **/

$(document).ready(function() {
	$('button#prescription-rights').on('click', function() {
		var doctorServiceNb = $('input[name="cityYbDoctorServiceNb"]').val();
		if (!doctorServiceNb.length) {
			WeKnow.errorMsg('请输入医保医师编码');
			$('input[name="cityYbDoctorServiceNb"]').focus();
			return false;
		} else {
			
			var params = [];
			params.push(doctorServiceNb);
			var ret = ZJHZ_YB_PLUGIN.func1310(params);
			if (ret.errcode == 0) {
				var outputDataCnt = ret.outputDataCnt;
				var outputData = ret.outputData;
				
				var idx = 0;
				var tbody = '';
				var rowIdx = 0;
				while(outputDataCnt-- > 0) {
					
					tbody += '<tr>';
						tbody += '<td>';
							tbody += ++rowIdx;
						tbody += '</td>';
						tbody += '<td>';
							tbody += outputData[idx]; // 医师编号
						tbody += '</td>';
						tbody += '<td>';
							tbody += outputData[idx + 1]; // 医师姓名
						tbody += '</td>';
						tbody += '<td>';
							tbody += outputData[idx + 2]; // 开始日期
						tbody += '</td>';
						tbody += '<td>';
							tbody += outputData[idx + 3]; // 终止日期
						tbody += '</td>';
						tbody += '<td>';
							tbody += outputData[idx + 4] == 1 ? '有效' : '无效'; // 有效标志
						tbody += '</td>';
						tbody += '<td>'; // 封锁标志
							var fsflgCd = outputData[idx + 5]; 
							if (fsflgCd == 0) {
								tbody += '违规';
							} else if (fsflgCd == 1) {
								tbody += '封锁';
							}
						tbody += '</td>';
						tbody += '<td>';
							tbody += outputData[idx + 6]; // 封锁原因
						tbody += '</td>';
					tbody += '</tr>';
					
					idx = idx + 7;
				}
				
				if (tbody.length) {
					var e = '';
					e += '<div class="modal fade" tabindex="-1" role="dialog">';
						e += '<div class="modal-dialog modal-lg" role="document">';
							e += '<div class="modal-content">';
								e += '<div class="modal-header">';
									e += '<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
									e += '<h4 class="modal-title">医师处方权信息</h4>';
								e += '</div>';
								e += '<div class="modal-body">';
									e += '<table class="table table-bordered table-hover table-condensed">';
										e += '<thead class="bg-default">';
											e += '<tr>';
												e += '<td>No</td>';
												e += '<td>医师编号</td>';
												e += '<td>姓名</td>';
												e += '<td>开始日期</td>';
												e += '<td>终止日期</td>';
												e += '<td>有效标志</td>';
												e += '<td>封锁标志</td>';
												e += '<td>封锁原因</td>';
											e += '</tr>';
										e += '</thead>';
										e += '<tbody>';
											e += tbody;
										e += '</tbody>';
									e += '</table>';
								e += '</div>';
							e += '</div>';
						e += '</div>';
					e += '</div>';
					
					$(e).appendTo('body').modal('show');
				} else {
					WeKnow.errorMsg('未查到该医师的医师处方权信息');
					return false;
				}
			} else {
				WeKnow.errorMsg('未查到该医师的医师处方权信息');
				return false;
			}
		}
	});
});